home *** CD-ROM | disk | FTP | other *** search
- #include "connect.h"
-
- // IUnknown methods
- HRESULT CLockBytesConnectionPoint::QueryInterface(REFIID riid, void** ppObject)
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(ppObject, sizeof(*ppObject)))
- {
- return E_POINTER;
- }
- if (riid==IID_IUnknown || riid==IID_IConnectionPoint)
- {
- *ppObject=(IConnectionPoint*) this;
- }
- else
- {
- return E_NOINTERFACE;
- }
- AddRef();
- return S_OK;
- }
-
- ULONG CLockBytesConnectionPoint::AddRef()
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- InterlockedIncrement((long*) &g_dwRefCount);
- InterlockedIncrement((long*) &m_dwRefCount);
- return m_dwRefCount;
- }
-
- ULONG CLockBytesConnectionPoint::Release()
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- ULONG dwRefCount=m_dwRefCount-1;
- InterlockedDecrement((long*) &g_dwRefCount);
- if (InterlockedDecrement((long*) &m_dwRefCount)==0)
- {
- delete this;
- return 0;
- }
- return dwRefCount;
- }
-
- // IConnectionPoint methods
- HRESULT CLockBytesConnectionPoint::GetConnectionInterface(IID FAR* pIID)
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(pIID, sizeof(*pIID)))
- {
- return E_POINTER;
- }
- *pIID=IID_ILockBytes;
- return S_OK;
- }
-
- HRESULT CLockBytesConnectionPoint::GetConnectionPointContainer(IConnectionPointContainer FAR* FAR* ppCPC)
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(ppCPC, sizeof(*ppCPC)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(m_pBA, sizeof(*m_pBA)))
- {
- return E_UNEXPECTED;
- }
- if (FAILED(m_pBA->QueryInterface(IID_IConnectionPointContainer, (void**) ppCPC)))
- {
- return E_UNEXPECTED;
- }
- return S_OK;
- }
-
- HRESULT CLockBytesConnectionPoint::Advise(LPUNKNOWN pUnkSink, DWORD FAR* pdwCookie)
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(pUnkSink, sizeof(*pUnkSink)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(pdwCookie, sizeof(*pdwCookie)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(m_pBA, sizeof(*m_pBA)))
- {
- return E_UNEXPECTED;
- }
- if (NULL!=m_pBA->m_pCacheArray && NULL!=m_pBA->m_pDataArray)
- {
- return CONNECT_E_ADVISELIMIT;
- }
- ILockBytes* pLB=NULL;
- if (FAILED(pUnkSink->QueryInterface(IID_ILockBytes, (void**) &pLB)))
- {
- return CONNECT_E_CANNOTCONNECT;
- }
- HRESULT hRes=E_UNEXPECTED;
- EnterCriticalSection(&m_pBA->m_sectLBConnect);
- if (NULL==m_pBA->m_pCacheArray)
- {
- m_pBA->m_pCacheArray=pLB;
- *pdwCookie=1;
- hRes=S_OK;
- }
- else if (NULL==m_pBA->m_pDataArray)
- {
- m_pBA->m_pDataArray=pLB;
- *pdwCookie=2;
- hRes=S_OK;
- }
- LeaveCriticalSection(&m_pBA->m_sectLBConnect);
- if (FAILED(hRes))
- {
- pLB->Release();
- }
- return hRes;
- }
-
- HRESULT CLockBytesConnectionPoint::Unadvise (DWORD dwCookie)
- {
- if (IsBadWritePtr(this, sizeof(*this)))
- {
- return E_POINTER;
- }
- if (IsBadWritePtr(m_pBA, sizeof(*m_pBA)))
- {
- return E_UNEXPECTED;
- }
- HRESULT hRes=CONNECT_E_NOCONNECTION;
- if (dwCookie==1 || dwCookie==2)
- {
- EnterCriticalSection(&m_pBA->m_sectLBConnect);
- if (dwCookie==1)
- {
- if (NULL!=m_pBA->m_pCacheArray)
- {
- m_pBA->m_pCacheArray->Release();
- m_pBA->m_pCacheArray=NULL;
- hRes=S_OK;
- }
- }
- else if (dwCookie==2)
- {
- if (NULL!=m_pBA->m_pDataArray)
- {
- m_pBA->m_pDataArray->Release();
- m_pBA->m_pDataArray=NULL;
- hRes=S_OK;
- }
- }
- LeaveCriticalSection(&m_pBA->m_sectLBConnect);
- }
- return hRes;
- }
-
- HRESULT CLockBytesConnectionPoint::EnumConnections(LPENUMCONNECTIONS FAR* ppEnum) {
- return E_NOTIMPL;
- }
-
- CLockBytesConnectionPoint::CLockBytesConnectionPoint(CAsyncByteArray* pBA)
- {
- m_dwRefCount=0;
- m_pBA=pBA;
- }
-
- CLockBytesConnectionPoint::~CLockBytesConnectionPoint()
- {
- m_pBA->m_pLBConnect=NULL;
- }
-